package com.exrobot.module.rbt.enums;

import com.exrobot.framework.common.core.ArrayValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum MqttTopicPubEnum implements ArrayValuable<String> {
    // ========== 机器人日志类型 ==========
    MEAL_CODE("/v1/devices/%s/meal-code", "meal-code"),
    MEAL_CODE_DELETE("/v1/devices/%s/meal-code-delete", "meal-code-delete"),
    UVLAMP_TASK("/v1/devices/%s/uvlamp-task", "uvlamp-task"),
    CHARGE_TASK("/v1/devices/%s/vehicle-charge-task","charge-task"),
    COMMON_TASK("/v1/devices/%s/task","task"),
    ORDER_DELIVERY("/v1/cloud/order-delivery","order-delivery"),
    MINIPRO_MESSAGE("/v1/cloud/minipro/message","minipro-message"),

    ;

    /**
     * 类型值
     */
    private final String typeVal;
    /**
     * 类型名
     */
    private final String typeName;

    public static final String[] ARRAYS = Arrays.stream(values()).map(MqttTopicPubEnum::getTypeVal).toArray(String[]::new);

    public static MqttTopicPubEnum validateTypeVal(String typeVal) {
        for (MqttTopicPubEnum typeEnum : MqttTopicPubEnum.values()) {
            if (typeEnum.getTypeVal().equals(typeVal)) {
                return typeEnum;
            }
        }
        throw new IllegalArgumentException("非法类型： " + typeVal);
    }

    public static MqttTopicPubEnum getEnum(String typeVal) {
        for (MqttTopicPubEnum typeEnum : MqttTopicPubEnum.values()) {
            if (typeEnum.getTypeVal().equals(typeVal)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static String getVal(String typeName) {
        for (MqttTopicPubEnum typeEnum : MqttTopicPubEnum.values()) {
            if (typeEnum.getTypeName().equals(typeName)) {
                return typeEnum.typeVal;
            }
        }
        return "";
    }

    public static String getName(String typeVal) {
        for (MqttTopicPubEnum typeEnum : MqttTopicPubEnum.values()) {
            if (typeEnum.typeName.equals(typeVal)) {
                return typeEnum.typeName;
            }
        }
        return "未知";
    }

    @Override
    public String[] array() {
        return ARRAYS;
    }
}
